//
//  MapBlock.m
//  ZeroWorld
//
//  Created by 马进 on 2018/2/9.
//  Copyright © 2018年 马进. All rights reserved.
//

#import "MapBlock.h"
#import "MainRole.h"
#import "MapArea.h"
@implementation MapBlock
- (instancetype)initMapBlockWith:(NSUInteger)mapid name:(NSString *)name area:(MapArea *)area outWays:(NSIndexPath *)outWays {
    self = [super init];
    if (self) {
        self.mapid = mapid;
        self.name = name;
        self.area = area;
        self.outWays = outWays;
    }
    return self;
}

//进入该地图可能会引发的事件
- (void)enter: (NSObject *)someone{
    if ([someone isKindOfClass:[MainRole class]]) {
        MainRole *r = (MainRole *)someone;
        [r feel:self];
    }
}

//离开该地图时可能引发的事件
- (void)exit:(NSObject *)someone{
}

// 寻找路径
- (MapBlock *)lookForWay:(MapDirection)idnex {
    NSUInteger index = (NSUInteger)idnex;
    if (self.outWays) {
        if (index < self.outWays.length) {
            NSUInteger mapid = [self.outWays indexAtPosition:index];
            if (mapid >= 1000) {
                return nil;
            }
            else {
                //从区域中获得相应的block
                if (self.area) {
                    return [self.area lookMapBlock:mapid];
                }
                return nil;
            }
        }
    }
    return nil;
}
@end


